package javahomework;
import java.util.Arrays;

//将数组元素从小到大排列序(直接插入排序)
public class text2 {

	    public static void main(String[] args){
	        int []array= {48,5,89,80,81,23,45,16,2};
	        System.out.println("未排序前的结果为："+Arrays.toString(array));
	        for (int i = 1; i < array.length; i++) {
	            while (i>0&&array[i]<array[i-1]){//防止下标出现负数
	                int center=array[i-1];
	                array[i-1]=array[i];
	                array[i]=center;
	                i--; //通过减一来继续排序
	            }
	        }
	        System.out.println("通过直接插入排序后结果为："+ Arrays.toString(array));
	    }
	}

